//@author A0105730U
#include "Parser_Importance.h"

 


Parser_Importance::Parser_Importance()
{
}


Parser_Importance::~Parser_Importance(void)
{
}


//Take in a input string, return ImportanceLevel, and generate the inputNoImpo 
std::string Parser_Importance::check(std::string input, std::string& inputNoImpo){
	std::size_t lastpos = input.find_last_not_of(QUOTE_BLANK_IMPORTANCE, input.size()-1);     //remove space
	if(lastpos == std::string::npos){
		inputNoImpo = input;
		return PRIORITY_NORMAL_PARSER;

	}else if(lastpos < 2){      // user type in ".low"
		inputNoImpo = input;
		return PRIORITY_NORMAL_PARSER;

	}else if(input.compare(lastpos-2, 3, PRIORITY_LOW_PARSER) == 0){
		std::size_t i = lastpos-2;

		if(i == 0){
			inputNoImpo = "";
			return PRIORITY_LOW_PARSER;
		}

		i = input.find_last_not_of(QUOTE_BLANK_IMPORTANCE, lastpos-3);

		if(i == std::string::npos){
			inputNoImpo = "";
			return PRIORITY_LOW_PARSER;
		}

		inputNoImpo = input.substr(0, i+1);
		return PRIORITY_LOW_PARSER;

	}else if(lastpos < 3){
		inputNoImpo = input;
		return PRIORITY_NORMAL_PARSER;

	}else if(input.compare(lastpos-3, 4, PRIORITY_HIGH_PARSER) == 0){
		std::size_t i = lastpos-3;
		
		if(i == 0){
			inputNoImpo = "";
			return PRIORITY_HIGH_PARSER;
		}

		i = input.find_last_not_of(QUOTE_BLANK_IMPORTANCE, lastpos-4);

		if(i == std::string::npos){
			inputNoImpo = "";
			return PRIORITY_HIGH_PARSER;
		}

		inputNoImpo = input.substr(0, i+1);
		return PRIORITY_HIGH_PARSER;

	}else if(lastpos < 5){
		inputNoImpo = input;
		return PRIORITY_NORMAL_PARSER;

	}else if(input.compare(lastpos-5, 6, PRIORITY_NORMAL_PARSER) == 0){
		std::size_t i = lastpos-5;

		if(i == 0){
			inputNoImpo = "";
			return PRIORITY_NORMAL_PARSER;
		}

		i = input.find_last_not_of(QUOTE_BLANK_IMPORTANCE, lastpos-6);

		if(i == std::string::npos){
			inputNoImpo = "";
			return PRIORITY_NORMAL_PARSER;
		}

		inputNoImpo = input.substr(0, i+1);
		return PRIORITY_NORMAL_PARSER;

	}else{
		inputNoImpo = input;
		return PRIORITY_NORMAL_PARSER;
	}
}

